package
{
	import View.GameOverView;
	import View.GameStartView;
	import View.GameView;
	import View.LoadView;
	
	import laya.display.Stage;
	import laya.events.Event;
	import laya.net.Loader;
	import laya.utils.Handler;
	
	/**
	 * 类描述
	 * @author sixsir
	 * @date 2016-11-24上午12:24:27
	 */
	public class DaDiShu
	{
		public static var gameStartView:GameStartView;
		public static var gameView:GameView;
		public static var gameOverView:GameOverView;
		private var loadView:LoadView;
		
		public function DaDiShu()
		{
			//初始化引擎
			Laya.init(800,600);
			Laya.stage.bgColor = "#FFCCCC";
			
			Laya.stage.alignV = Stage.ALIGN_MIDDLE;
			Laya.stage.alignH = Stage.ALIGN_CENTER;
			Laya.stage.screenMode = Stage.SCREEN_HORIZONTAL;
			
			Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
			
//			Stat.show(Browser.clientWidth - 120, 0);
			
			Laya.loader.load("res/atlas/load.json", Handler.create(this, onLoadingLoaded), null, Loader.ATLAS);
			
			// 侦听加载失败
			Laya.loader.on(Event.ERROR, this, onError);
		}
		
		private function onError(err:String):void
		{
			trace("加载失败: " + err);
		}
		
		private function onLoadingLoaded():void
		{
			loadView = new LoadView();
			Laya.stage.addChild(loadView);
			
			var resAry:Array = [{url:"res/atlas/ui.json", type:Loader.ATLAS}, {url:"ui/back.png", type:Loader.IMAGE}, {url:"ui/help.png", type:Loader.IMAGE}];
			Laya.loader.load(resAry, Handler.create(this, onLoaded), Handler.create(this, onLoading, null, false));
		}
		
		private function onLoading(progress:Number):void
		{
			loadView.progressBar.value = progress;		
		}
		
		private function onLoaded():void
		{
			loadView.removeSelf();
			
			gameStartView = new GameStartView();
			Laya.stage.addChild(gameStartView);
		}
	}
}